package com.superteam.zzl.activity;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.superteam.zzl.activity.databinding.ActivityImageBinding;
import com.superteam.zzl.activity.implement.IImageActivityEvent;
import com.superteam.zzl.adapter.ImageActivityAdapter;
import com.superteam.zzl.model.DynamicFragment.bean.Dynamic;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class ImageActivity extends AppCompatActivity implements IImageActivityEvent {

    private ActivityImageBinding db;
    private List<String> list;
    private boolean isClick;
    private int pos;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getSupportActionBar().hide();
        super.onCreate(savedInstanceState);
        db = DataBindingUtil.setContentView(this, R.layout.activity_image);
        db.vp.setAdapter(new ImageActivityAdapter(this, getData()));
        db.vp.setCurrentItem(pos);
    }

    private List<String> getData() {
        list = new ArrayList<String>();
        Intent intent = getIntent();
        Serializable data0 = intent.getSerializableExtra("data0");
        if (data0 != null) {
            list.add((String) data0);
        } else {
            Serializable data1 = intent.getSerializableExtra("data1");
            pos = intent.getIntExtra("pos", 0);
            List<Dynamic.DataBean.TrendsListBean.ImageListBean> data = (List<Dynamic.DataBean.TrendsListBean.ImageListBean>) data1;
            for (Dynamic.DataBean.TrendsListBean.ImageListBean imageListBean : data) {
                list.add(imageListBean.image_url);
            }
        }
        return list;
    }

    @Override
    public void myClick(View view) {
        if (!isClick) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                db.vp.setBackground(new ColorDrawable(Color.WHITE));
            }
        } else {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                db.vp.setBackground(new ColorDrawable(Color.BLACK));
            }
        }

        isClick = !isClick;
    }
}
